(function ({form,table,layer,laydate,tableIns,url,contentType,ok,AjaxFn}) {

    /*form.render(),*/

    tableIns = table.render({
        elem:'#userTable',
        url:url+"getTableList",
        method:'post',
        contentType,
        page:{first: '首页', last: '尾页', prev: '上一页', next: '下一页', layout: ['count','prev', 'page', 'next'], groups: 5, theme: '#1e9fff', limits:[10,20,30,40,50],},
        cols: [
            [
                { title: '序号',type:'numbers',fixed:"left",unresize: true, align: "center", minWidth: 100},
                { title: '操作',fixed:"left",unresize: true, align: "center",width:220, minWidth: 200,templet:function (d,updata = '',start='',forbid='') {
                        updata = '<button type="button" class="layui-btn layui-btn-xs updata-btn-color" lay-event="updata"><i class="layui-icon">&#xe642;</i>修改</button>';
                        d.vtypt==1?(function () {
                            start ='<button type="button" disabled class="layui-btn layui-btn-xs layui-btn-disabled" lay-event="start"><i class="layui-icon">&#xe683;</i>启用</button>',
                            forbid ='<button type="button" class="layui-btn layui-btn-xs forbid-btn-color" lay-event="forbid"><i class="layui-icon">&#xe673;</i>禁用</button>';
                        })():
                        (function () {
                            start ='<button type="button" class="layui-btn layui-btn-xs start-btn-color" data-ddd="111" lay-event="start"><i class="layui-icon">&#xe683;</i>启用</button>',
                            forbid ='<button type="button" disabled class="layui-btn layui-btn-xs layui-btn-disabled" lay-event="forbid"><i class="layui-icon">&#xe673;</i>禁用</button>';
                        })();
                        return `<div>${updata}${start}${forbid}</div>`;
                    }
                },
                {field: 'vtypt', title: '状态', unresize: true, align: "center", width:80,minWidth: 80,templet:function (d) {return d.vtypt==1?`<div>启用</div>`:`<div>禁用</div>`;}},
                {field: 'userid', title: '账号', unresize: true, align: "center",width:120, minWidth: 100},
                {field: 'username', title: '用户名称', unresize: true, align: "center", minWidth: 100},
                {field: '', title: '创建时间', unresize: true, align: "center",width:120, minWidth: 150,templet:function (d) {
                        return `<div><span>${d.insdate}</span></div>`
                    }
                },
            ]
        ]
    }),
    table.on('tool(userTable)', function({data,event,tr}){

        event=="updata"?(function(){
            layer.open({

                anim: 4,
                type: 2,
                resize:false,
                skin: 'add-but-open',
                title: ['编辑', 'font-size:18px; background-color:#e7eaec;'],
                area: ['aotu'],
                btn: ['取消','修改'],///declare/scienceResults/getUpdata?id=
                content: url + "getUpdata/"+data.userid,
                btn2: function(index, layero){
                    var body = layer.getChildFrame('body', index);
                    body.find('#submit').click();
                    return false;
                },
                end: function () {
                   tableIns.reload();
                }
            }
            ),$('.add-but-open iframe').css('height', '100%'),
              $(".layui-layer-btn").css({"padding-top":"0px","padding-bottom": "3px","background-color":"rgb(231, 234, 236)"});
        })():event=="start"?(function(){
            layui.layer.confirm("确定启用该用户吗？", {
                id: "uptypeById",
                icon: 3, anim: 4, title: '提示',
                btn: ['取消','启用'],
                success: function (layero) {
                    let btn = layero[0].getElementsByClassName('layui-layer-btn')[0].getElementsByTagName('A')[0];btn.href = 'javascript:void(0)', btn.focus();},
                btn2: function(index, layero){
                    data.vtypt==1?data.vtypt=0:data.vtypt=1;
                    data.startAndForbid="启用"
                    let {code,msg,icon=0} = AjaxFn(url+"uptypeById",JSON.stringify(data),{});
                    code==200?icon=1:icon=5;
                    layer.msg(msg,{icon: icon})
                },
                end:function () {
                    tableIns.reload();
                }
            });
        })():event=="forbid"?(function(){
            layui.layer.confirm("确定禁用该用户吗？", {
                id: "uptypeById",
                icon: 3, anim: 4, title: '提示',
                btn: ['取消','禁用'],
                success: function (layero) {
                    let btn = layero[0].getElementsByClassName('layui-layer-btn')[0].getElementsByTagName('A')[0];btn.href = 'javascript:void(0)', btn.focus();
                    },
                btn2: function(index, layero){
                    data.vtypt==0?data.vtypt=1:data.vtypt=0;
                    data.startAndForbid="禁用"
                    let res = AjaxFn(url+"uptypeById",JSON.stringify(data),{});
                    layui.layer.close(index);
                },
                end:function () {
                    tableIns.reload();
                }
            });
        })():'';

    }),
    form.verify({
        custompassword:function (value, item) {
            if (value.length<6){
                $("#"+$(item).attr("data-p")).text("密码长度最小为6位")
                return "密码长度最小为6位";
            }
            if(!/^[a-zA-Z0-9]+$/.test(value)){
                return "密码只能以数字和字母组成";
            }
            $("#"+$(item).attr("data-p")).text("")
        }
    }),

    form.on('submit(useradd)', function(data){
        let {userid,username,password} =  data.field
        data.field = {userid:userid.trim(),username:username.trim(),password:password.trim()}
        let {msg,code} = AjaxFn(url+"addUser",JSON.stringify(data.field),{});
        code=="200"?(function () {
            layer.msg(msg,{icon: 6}),
            $(".useradd-primary").click(),
            tableIns.reload();
        })():(function () {
            layer.msg(msg,{icon: 5})
            code!=5002?$("input[name=userid]").focus().addClass("layui-form-danger"):'';
        })();
        return false;
    }),

    form.on('submit(table)', function(data){
        tableIns.reload({
            where:data.field,
            page: {curr: 1}
        });
        return false;
    })

})({
    form: layui.form,
    table: layui.table,
    layer: layui.layer,
    laydate:layui.laydate,
    tableIns: '',
    b:0,
    url: "/evaluation/userInput/",
    contentType: 'application/json;charset=utf-8',
    ok:function(msg,icon){
        layui.layer.confirm(msg, {
            id: "ok",
            icon: icon,
            anim: 4,
            title: '提示',
            btn:['确定'],
            success: function (layero) {
                var btn = layero[0].getElementsByClassName('layui-layer-btn')[0].getElementsByTagName('A')[0];
                btn.href = 'javascript:void(0)';
                btn.focus();
            },
            btn2: function(index, layero){
                layui.layer.close(index);
            },
            end:function () {}
        });
        return b;
    },
    AjaxFn:function (url,data,resource) {
        $.ajax({
            url,
            contentType:'application/json;charset=utf-8',
            type:'post',
            async:false,
            data,
            success:function(res) {
                let {msg='',code=''} =res;
                msg=='' && code==''? top.location.reload() : "";
                resource = res;
            }
        });
        return resource;
    }
})